<?php
namespace Content\Controller;
use Common\Controller\AdminbaseController;
class SlideController extends AdminbaseController 
{   
	protected $slideObj;
    public function _initialize()
    {
      parent::_initialize();
        $this->slideObj = D("Slide");
    }

	public function index()
	{
			$this->lists();
	}
	public function lists()
	{
      $count      =  $this->slideObj->count();
      $Page       = new \Think\Page($count,15);
      $show       = $Page->show();
      $list = $this->slideObj->order(array("listorder" => "ASC","id" => "ASC"))->limit($Page->firstRow.','.$Page->listRows)->select();
      $this->assign('list',$list);
      $this->assign('page',$show); 
      $this->display('list');
	}

    public function add()
    {
    	$this->display();
    }
    public function edit($id=0)
    {
    	if ($id>0) 
    	{
            $slideObj = $this->slideObj->find($id);
            $this->assign("slide",$slideObj);
            $this->display();
    	}else{
    	   $this->display("add");
        }
        
    }
    public function save()
    {
        $id = I('post.inputId','-1','htmlspecialchars');
        $title = I('post.inputTitle','','htmlspecialchars');
        $url = I('post.inputUrl','','htmlspecialchars');
        $description = I('post.inputDescription','','htmlspecialchars');
        $image = I('post.inputImageId','','htmlspecialchars');
        $status = I('post.inputStatus','','htmlspecialchars');
        $data = array();
        $data["title"]  = $title;
        $data["url"]  = $url;
        $data["description"] = $description;
        $data["imageid"] = $image;
        $data['createtime'] =time();
        $data['status'] = $status;
        if($id>0)
        {
            $editResult = $this->slideObj->where("id=%d",$id)->save($data);
            $arr = array("status"=>'1',"message"=>"编辑幻灯片成功","url"=>"index");
        }
        else
        {
            $addResult =  $this->slideObj->add($data);
            if($addResult) {
                $arr = array("status"=>'1',"message"=>"添加幻灯片成功","url"=>"index");
            }else{
                $arr = array("status"=>'0',"message"=>"添加幻灯片失败");
            }
        }
        echo json_encode($arr);
    }
    /*排序更新*/
    public function listorder()
    {
       $ids = I('post.ids','-1','htmlspecialchars');
       $listorders = I('post.listorders','','htmlspecialchars');
       parent::_listorder($this->slideObj,$ids,$listorders);
    }
    /*单个删除 id*/
    public function delete($id)
    {
        parent::_delete($this->slideObj,$id);
    }
    /* 批量删除 ids*/
    public function checkDeletes($ids)
    {
      parent::_checkDeletes($this->slideObj,$ids);
    }
    /* 单个修改当前状态status 0 1 -1*/
    public function changeStatus($id,$status)
    {
        parent::_changeStatus($this->slideObj,$id,$status);
    }
    /*批量 修改当前状态status 0 1 -1*/
    public function checkChanges($status,$ids)
    {
      parent::_checkChanges($this->slideObj,$status,$ids);
    }
}
?>